﻿using System;
using System.Configuration;
using System.Data;
using mojoPortal.Net;
using mojoPortal.Web;
using Resources;
using mojoPortal.Web.Framework;
using System.Collections;
using mojoPortal.Business;
using ud_gSDMS.Code_Service;
using mojoPortal.Business.WebHelpers;
namespace ud_gSDMS.contract
{
    public partial class Contract_Report_Detail : mojoBasePage
    {
        private int pageId = -1;
        private int moduleId = -1;
        private string id;

        void Page_Load(object sender, EventArgs e)
        {
            //if (!UserCanEditPage() || !UserCanViewPage())
            //{
            //    WebUtils.SetupRedirect(this, SiteRoot + "/AccessDenied.aspx");
            //}


            if (!Page.IsPostBack)
            {
                PopulateLabels();
                PopulateControls();

            }
        }

        private void PopulateLabels()
        {

        }
        private void PopulateControls()
        {
            var data = gSDMS_BL.ud_gSDMS_CONTRACT_Get(id);

            //CONTRACT INFORMATION:
            txtContract_Code.Text = data.Contract_Code;
            txtContract_Name.Text = data.Contract_Name;
            txtContract_Date.Text = data.Contract_Date.Value.ToShortDateString();
            txtStart_Date.Text = data.Start_Date.Value.ToShortDateString();
            txtEnd_Date.Text = data.End_Date.Value.ToShortDateString();
            txtCat_Product_Package_ID.Text = data.ud_gSDMS_CAT_PRODUCT_PACKAGE.Name;
            txtResource.Text = data.Resource.ToString();

            //CUSTOMER INFORMATION:
            txtCustomer_Code.Text = data.Customer_Code;
            txtCustomer_Name.Text = data.Customer_Name;
            txtCustomer_Phone.Text = data.Customer_Phone;
            txtCustomer_Fax.Text = data.Customer_Fax;
            txtCustomer_Email.Text = data.Customer_Email;
            txtContact_Name_1.Text = data.Contact_Name_1;
            txtContact_Name_2.Text = data.Contact_Name_2;
            txtContact_Phone_1.Text = data.Contact_Phone_1;
            txtContact_Phone_2.Text = data.Contact_Phone_2;
            txtContact_Email_1.Text = data.Contact_Email_1;
            txtContact_Email_2.Text = data.Contact_Email_2;


            //OTHER INFORMATION:
            txtAccount_Manager.Text = data.mp_User.LoginName;
            txtAssigned_To.Text = data.mp_User1.LoginName;
            txtNotes.Text = data.Notes;

            txtNotes.WebEditor.ToolBar = mojoPortal.Web.Editor.ToolBar.SimpleWithSource;
            txtNotes.WebEditor.Height = 200;
        }


        #region event
        #endregion

        #region OnInit

        protected override void OnPreInit(EventArgs e)
        {
            AllowSkinOverride = true;
            base.OnPreInit(e);
            Load += Page_Load;
        }

        protected override void OnInit(EventArgs e)
        {
            LoadParams();
            LoadPanels();
            base.OnInit(e);

            SiteUtils.SetupEditor(txtNotes);
            //btnFinish.Click += btnFinish_Click;
            SuppressPageMenu();
        }





        //void btnFinish_Click(object sender, EventArgs e)
        //{
        //    WebUtils.SetupRedirect(this, SiteUtils.GetCurrentPageUrl());
        //}

        private void LoadParams()
        {
            pageId = WebUtils.ParseInt32FromQueryString("pageid", pageId);
            moduleId = WebUtils.ParseInt32FromQueryString("mid", true, moduleId);
            id = WebUtils.ParseStringFromQueryString("id", id);
        }

        private void LoadPanels()
        {
            Hashtable settings = ModuleSettings.GetModuleSettings(moduleId);
            //config = new ContactFormConfiguration(settings);
            bool showLeftColumnAdmin = ConfigHelper.GetBoolProperty("ShowLeftColumnAdmin", false);
            bool showRightColumnAdmin = ConfigHelper.GetBoolProperty("ShowRightColumnAdmin", false);
            bool showTopColumnAdmin = ConfigHelper.GetBoolProperty("ShowTopColumnAdmin", false);
            bool showBottomColumnAdmin = ConfigHelper.GetBoolProperty("ShowBottomColumnAdmin", false);
            int showCenterColumnAdmin = ConfigHelper.GetIntProperty("ShowCenterColumnAdmin", 0);
            LoadSideContent(showLeftColumnAdmin, showRightColumnAdmin, showTopColumnAdmin, showBottomColumnAdmin, showCenterColumnAdmin);
        }
        #endregion
    }
}